<?php
namespace app\admin\controller;

use app\admin\model\Users;
use think\Controller;
use think\Cookie;
use think\Request;
use think\Session;

class Index extends Controller{

    public function _initialize(){
        if(session('?user')){
            return $this->redirect('home/index');
        }
    }

    public function index(){

        $mess = Session::get('mess');
        Session::delete('mess');
        return $this->fetch('index',[
            'mess' => $mess
        ]);
    }

    public function login(){
        $mess = ['status'=>2,'mess'=>'请登陆之后在操作！'];
        if(Request::instance()->isPost()){
            $post = Request::instance()->post();
            $users = new Users();
            $user = $users->Login($post);
            if($post['save_pass'] == 'on'){
                Cookie::set('user',$user);
            }
            return $this->redirect('home/index');
        }

        Session::set('mess',$mess);
        return $this->redirect('index/index');
    }

}